<template>
    <div>
        <!--页面路径-->
        <div>
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>商品管理</el-breadcrumb-item>
                <el-breadcrumb-item>{{ this.$route.params.name }}</el-breadcrumb-item>
            </el-breadcrumb>
        </div>

        <!--页面内容-->
        <div style="background:#fff;margin-top:20px;padding:20px 10px;">
            <!--所有操作按钮：添加、删除、查询-->
            <div style="">
                <el-row>
                    <el-col :span="12" style="text-align:left;">
                        <el-button type="primary" size="medium" @click="dialogFormVisible = true">添加</el-button>
                        <el-button type="danger" size="medium">批量删除</el-button>
                    </el-col>
                    <el-col :span="12" style="text-align:right;">
                        <el-input size="medium" style="width:200px;"></el-input>
                        <el-button type="success" size="medium">查询</el-button>
                    </el-col>
                </el-row>
            </div>

            <el-divider></el-divider>

            <!--数据列表-->
            <div>
                <el-table :data="tableData" style="width: 100%;margin-bottom: 20px;" row-key="id"  :default-expand-all="false"
                    :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
                    <el-table-column prop="name" label="姓名" sortable width="180"></el-table-column>
                    <el-table-column prop="address" label="地址"></el-table-column>

                    <el-table-column label="操作" width="180">
                        <template slot-scope="scope">
                            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                            <el-button size="mini" type="danger"
                                @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>


            </div>

            <!--分页-->
            <div style="margin-top:30px;">
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                    :current-page="pages.pageIndex" :page-sizes="[1, 2, 5, 8, 10, 15, 20]" :page-size="pages.pageSize"
                    layout="total, sizes, prev, pager, next, jumper" :total="pages.total">
                    <!-- <template slot-scope="scope">
                        <span>{{ scope.row.home }}</span>
                    </template> -->
                </el-pagination>
            </div>
        </div>

        <!--弹出框-->
        <div>
            <el-dialog title="添加用户" :visible.sync="dialogFormVisible">
                <el-form :model="form">
                    <el-form-item label="活动名称" :label-width="formLabelWidth">
                        <el-input v-model="form.name" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="活动区域" :label-width="formLabelWidth">
                        <el-select v-model="form.region" placeholder="请选择活动区域">
                            <el-option label="区域一" value="shanghai"></el-option>
                            <el-option label="区域二" value="beijing"></el-option>
                        </el-select>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisible = false">取 消</el-button>
                    <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
</template>


<script>
export default {
    data() {
        return {
            tableData: [],
            pages: {
                pageIndex: 1,
                pageSize: 8,
                total: 0
            },
            dialogFormVisible: false,
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            },
            formLabelWidth: '120px'
        }
    },
    mounted() {
        this.onloadCategory()
    },
    methods: {
        //加载分类级联选择器数据
        onloadCategory(){
            let url=this.$baseUrl +'/category'
            this.$http.get(url).then(res=>{
                if (res.data.code == 200) {
                    this.tableData = res.data.data.items
                    this.pages.total = res.data.data.total
                }
            })
        },

        //行编辑按钮事件
        handleEdit(index, row) {
            console.log(index, row);
        },
        //行删除按钮事件
        handleDelete(index, row) {
            console.log(index, row);
        },
        //分页事件
        handleSizeChange(val) {
            this.pages.pageSize = val
            this.onloadData()
        },
        //分页事件
        handleCurrentChange(val) {
            this.pages.pageIndex = val
            this.onloadData()
        }
    },
}
</script>